# coding = utf-8

'''
数据读取
'''

import os
import pydicom
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
from medpy.io import load, save
import SimpleITK as sitk


def read_data():
    root = "/datasets/qiye/image_venous"
    file_list = sorted(os.listdir(root))

    label_root = "/datasets/qiye/liver"
    label_file_list = sorted(os.listdir(label_root))

    file_name = os.path.join(root, file_list[45])
    data = sitk.GetArrayFromImage(sitk.ReadImage(file_name))

    artery = "/datasets/qiye/image_arterial"
    artery_file_list = sorted(os.listdir(artery))
    artery_file_name = os.path.join(artery, artery_file_list[45])
    artery = sitk.GetArrayFromImage(sitk.ReadImage(artery_file_name))

    mask_file = os.path.join(label_root, label_file_list[45])
    mask = sitk.GetArrayFromImage(sitk.ReadImage(mask_file))

    fusion_image = Image.open("/home/diaozhaoshuo/log/BeliefFunctionNN/chengkung/dongbeidaxue/munet/image_tumor/case_00045/fusion/219.png")

    plt.subplot(1, 3, 1)
    t = data[219]
    t[t<=-250] = -250
    t[t>250] = 250

    y = artery[219]
    y[y<=-250] = -250
    y[y>250] = 250
    plt.imshow(abs(t-y), cmap="gray")
    print(np.min(t-y), np.max(t-y))

    plt.subplot(1, 3, 2)
    plt.imshow(fusion_image)

    plt.subplot(1, 3, 3)
    x = data[219] * mask[219]
    print(np.min(x), np.max(x))
    plt.imshow(data[219] * mask[219], cmap="gray")

    plt.show()

if __name__ == '__main__':
    read_data()